#filename "filerna.smc"
#offset $0000
#romtype lorom

code DMA_Xfer{

; This is a comment. Whee!
; Note that -ALL- of the addresses here are LoROM!
; NONE of them are absolute!

%position $02895F
JSL $1FE300  ;Here, we overwrite the old JSL that decompressed the font.
             ;Read the log to find out how this address was determined.
             ;If you don't have a 4-byte JSL or load to overwrite, then
             ;you'll need to overwrite more than one command and reproduce
             ;them in your DMA routine.

%position $1FE300 ;1FE300 is some blank space before our font. Yay.

LDA #$00    ;$4300 is the DMA control register. Unless you're writing directly to vram,
STA $4300   ;this should probably always be zero.

LDA #$80    ;$4301 is the destination register. The upper address is assumed to be $21,
STA $4301   ;so you're gonna have to figure out which of the $2100-$21FF registers you
            ;want to write to.

LDA #$00    ;...in our case, since we're writing to WRAM ($7E:0000-$7F:FFFF), we need to
STA $2181   ;use $2180. We store the address that $2180 goes to in $2181-$2183. I'm going
LDA #$11    ;to leave these blank, but they're in standard pointer format. Of note is that
STA $2182   ;bank $7E must be written as $00, and $7F must be written as $01.
LDA #$01    ;So, if you were writing to $7F:9320 you'd write $20, $93, $01 in that order
STA $2183   ;to $2181, $2182, and $2183 in that order.

LDA #$00    ;These registers contain the address your read starts from. Since we're dealing
STA $4302   ;with loroms, you need to remember how lorom addressing works, and you'll need
LDA #$F0    ;to convert the address of your new font ($FF000, right?) to a standard 24-bit
STA $4303   ;LoROM pointer. I'll leave these blank as well.
LDA #$1F    ;You should be able to fill them in yourself.
STA $4304

LDA #$00    ;$4305 and $4306 are the number of bytes you need to copy. Again, the order of
STA $4305   ;the bytes is the same as before -- the high byte of your address comes LAST.
LDA #$10    ;Notice that you can't exceed 64K in this. That's cuz of the bank boundaries.
STA $4306   ;Don't try to copy more than 32K if you're dealing with loroms, either.
            ;Note that since you're not doing -addresses-, counting here starts from $0,
            ;not $8000, like lorom addresses would.

LDA #$01    ;This register starts DMA! Note that there are 8 DMA channels that can be used
STA $420B   ;if you want to do more than one DMA at a time (channels 0-7.) We're using
            ;Channel 0. If we wanted to use channel 1, we'd be writing to $431X instead of
            ;$430X. The same holds for the rest of the DMA channels.
            ;Note that writing a byte to $420B can start more than one channel at a time!
            ;Since we're writing #$01 to it (00000001 binary), we're starting channel 0.
            ;If we wrote #$02 (00000010 binary), we'd start channel 1.
            ;If we wrote #$03, we'd start channels 0 -and- 1!

RTL         ;Kay, we're done!
}